﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VIKI.IDAL;
using VIKI.LINQ;
using VIKI.Support;

namespace VIKI.LINQDAL
{
    public class UserDAL : IUserDAL
    {
        private vikiDataContext context = new vikiDataContext();

        public Guid Insert(User user)
        {
            try
            {
                context.User.InsertOnSubmit(user);
                context.SubmitChanges();
                return user.UserId;
            }
            catch (Exception e)
            {
                throw new VikiException("注册用户失败", e);
            }
        }

        public void Update(User user)
        {
            throw new NotImplementedException();
        }

        public void Delete(Guid userId)
        {
            throw new NotImplementedException();
        }

        public User FindUserById(Guid userId)
        {
            return (from user in context.User where user.UserId == userId select user).Single();
        }

        public User FindUserByName(string userName)
        {
            return (from user in context.User where user.UserName == userName select user).Single();
        }

        public User FindUserByEmail(string email)
        {
            return (from user in context.User where user.UserEmail == email select user).Single();
        }
    }
}
